import user from "@/mock/modules/user";
import { defineStore } from "pinia";

export const useGlobalStore = defineStore("globalData", {
  // 数据存到store里刷新页面会重置，持久化就不会了
  persist: {
    enabled: true, //开启数据持久化
    strategies: [
      {
        key: "staticState", //给一个要保存的名称
        storage: localStorage, //sessionStorage / localStorage 存储方式
      },
    ],
  },
  state: () => {
    return {
      navTitle: '', // 导航标题
      blogMeta: {},
      user: {},
      isDark: window.matchMedia('(prefers-color-scheme: dark)').matches,
    };
  },
  actions: {
    updateNavTitle(title) {
      // 更新目录数据
      this.navTitle = title;
    },
    updateTheme(isDark) {
      this.isDark = isDark;
    },
  },
});
